package yxy.game.pm2.command.camptower;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.CampTowerMessage;
import yxy.game.pm2.module.battle.BattleType;
import yxy.game.pm2.module.camptower.CampTowerHandle;

/**
 * 星星领奖请求
 *
 * @ClassName CMD_CampTowerStarTargetReceive
 * @Author jingtao-zheng
 * @Date 2022/8/8 10:48
 * @Version 1.0
 **/
@MessageType(proto = Command.CampTowerStarTargetReceive, classtype = CampTowerMessage.CampTowerStarTargetReceiveRequest.class)
public class CMD_CampTowerStarTargetReceive extends Command<CampTowerMessage.CampTowerStarTargetReceiveRequest> {
    @Override
    public void execute(MessageSource messageSource, CampTowerMessage.CampTowerStarTargetReceiveRequest request) throws Exception {
        String playerCode = messageSource.getTag();
        //获取阵营塔类型
        int type = request.getType().getNumber();
        //领奖id
        int box = request.getBox();
        CampTowerMessage.CampTowerStarTargetReceiveResponse.Builder response = CampTowerMessage.CampTowerStarTargetReceiveResponse.newBuilder();
        BattleType battleType = CampTowerHandle.matchBattleType(type);
        Result result = new CampTowerHandle(battleType).starReward(playerCode, box, response, type);

        send(messageSource, response, result);
    }


    private void send(MessageSource messageSource, CampTowerMessage.CampTowerStarTargetReceiveResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}
